# +--------------------------
# | User: zq                -
# | Version: python3.7      -
# | Time: 2020-03-17 09:25                
# +--------------------------
import time
from selenium import webdriver

url = "https://www.fastadmin.net/user/login.html"
brower = webdriver.Chrome(
    executable_path="/Users/zhangqiang/Desktop/05-python/03-spider-learn/spider/csdn_spider/chromedriver")


def login():
    username = "ziyuzile22"
    password = "zl4921272"

    # 进入页面
    brower.get(url)

    # 找到用户名,密码节点
    username_ele = brower.find_element_by_xpath("//input[@id='account']")
    password_ele = brower.find_element_by_xpath("//input[@id='password']")

    # 写入密码
    username_ele.send_keys(username)
    password_ele.send_keys(password)

    # 延迟3秒
    time.sleep(3)

    # 找到登录框
    submit_ele = brower.find_element_by_xpath("//button[@class='btn btn-primary btn-md btn-block']")
    # 点击登录
    submit_ele.click()

    # 延迟5秒
    time.sleep(5)

    # 找到签到按钮,点击进入签到页面
    qiandao_ele = brower.find_element_by_xpath("//*[@id='content-container']/div/div[1]/div/ul[1]/li[7]/a")
    qiandao_ele.click()

    # 延迟5秒,点击签到
    click_qiandao_ele = brower.find_element_by_xpath("//a[@class='btn btn-success pull-right btn-signin ']")
    click_qiandao_ele.click()

    # 延迟2秒关闭
    brower.close()


if __name__ == "__main__":
    login()
